/** \file    refine/bit_mask.h
  * \brief   Moves across the mask and adds or removes single pixels to it 
  *			 according to color ditribution in image.
  * \date    2003
  * \author  Fedor Chelnokov
  * \version $Header: /home/cscom1r4/cvsroot/cs/include/refine/bit_mask.h,v 1.12 2006/01/15 07:31:32 cscom1r4 Exp $
  */

#ifndef _refine_bit_mask_h_
#define _refine_bit_mask_h_

#include "types.h"
#include "information_source.h"
#include "typelib/affine.h"

namespace refine {

namespace bit_mask {

enum change_type {
	turn_on_and_off,
	turn_on_only,
	turn_off_only
};

struct params 
{
	params(); ///< loads default params

	int		whs; ///< window half size: [1, 127]
	bool	auto_t;
	float	t; ///< decision threshold, >1
	int		max_passes; ///< [1, ...]
	information consider;
	change_type change;
	preference prefer;
	bool	silent;

	mask *	modifiable; ///< 0 means every pixel is permitted to change
};

bool operator == (const params & lhs, const params & rhs);

/// refine in one (target) frame without teacher
void adjust(
	const byte_image & im, mask & m, 
	const params & p = params(),
	bool check_once = false ///< don't test a pixel again after mask value for it was changed once
);
void adjust(
	const argb_byte_image & im, mask & m, 
	const params & p = params(),
	bool check_once = false ///< don't test a pixel again after mask value for it was changed once
);

/// transfer mask from reference frame to target frame using predicted motion if available
void track(
	const byte_image & ref_im, const mask & ref_m, 
	const byte_image & tgt_im, mask & tgt_m, 
	information_source isource,
	const affine * motion = 0,	///< contains estimated transformtaion of object from reference to target frames
	const params & p = params()
);

} //namespace bit_mask

} //namespace refine

#endif //_refine_bit_mask_h_